//
//  PeiSongDuanMyDingDVController.m
//  Experss
//
//  Created by 嗯，大葱 on 17/8/11.
//  Copyright © 2017年 嗯，大葱. All rights reserved.
//

#import "PeiSongDuanMyDingDVController.h"
#import "LieShouZhiWeiView.h"
#import "PeiSongPopView.h"
#import "PSP2View.h"

#import "DingDanList2Cell.h"
#import "DingDanDetailViewController2.h"
#import "PublicMapVController.h"

@interface PeiSongDuanMyDingDVController ()<chooseLieShouMainBtnDelegate,UITableViewDataSource, UITableViewDelegate,remoPeiSongPopOneDelegate,remoPeiSongPopOne2Delegate,UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)NSArray *dataArray;


@property (nonatomic, strong)LieShouZhiWeiView *lieShouZhiWeiView;
@property (nonatomic, strong)PeiSongPopView *peiSongpopView;

@property (nonatomic, strong)PSP2View *psp2View;

@end

@implementation PeiSongDuanMyDingDVController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configureNaBar];
    [self configureVC];
    _dataArray =@[@[@{@"1":@"2"},@{@"3":@"4"}],@[@{@"1":@"2"},@{@"1":@"9"}],@[@{@"1":@"2"},@{@"1":@"8"}]];
}
- (void)configureNaBar {
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    self.navigationItem.title = @"我的订单";
    //设置导航栏按钮的边距
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame= CGRectMake(0, 0, 60, 30);
    [rightBtn setImage:[UIImage imageNamed:@"all_fanhui2"] forState:(UIControlStateNormal)];
    [rightBtn addTarget:self action:@selector(handleBackAxtion) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *btn_left = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    UIBarButtonItem *negativeSpacerleft = [[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace   target:nil action:nil];
    /**
     width为负数时，相当于btn向右移动width数值个像素，由于按钮本身和  边界间距为5pix，所以width设为-5时，间距正好调整为0；width为正数 时，正好相反，相当于往左移动width数值个像素
     */
    negativeSpacerleft.width = -20;
    self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:negativeSpacerleft, btn_left, nil];
    
    
    
}
- (void)handleBackAxtion {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)configureVC {
    
    self.view.backgroundColor = KShouYeBg;
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 45, kScreen_Width, kScreen_Height-45) style:(UITableViewStyleGrouped)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = kSpNone;
    _tableView.backgroundColor = KShouYeBg;
    [self.view addSubview:_tableView];
    [_tableView registerNib:[UINib nibWithNibName:@"DingDanList2Cell" bundle:nil] forCellReuseIdentifier:@"DingDanList2Cell"];
    
    
    _lieShouZhiWeiView = [[LieShouZhiWeiView alloc] initWithFrame:CGRectMake(0, 64, kScreen_Width, 45)];
    _lieShouZhiWeiView.backgroundColor = [UIColor whiteColor];
    _lieShouZhiWeiView.delegate = self;
    _lieShouZhiWeiView.oneBtn.selected = YES;
    _tempBtn =  _lieShouZhiWeiView.oneBtn;
    [self.view addSubview:_lieShouZhiWeiView];
    
    _peiSongpopView = [[PeiSongPopView alloc] initWithFrame:CGRectMake(0,kScreen_Height, kScreen_Width, kScreen_Height)];
    _peiSongpopView.dataArary = @[@"周",@"月"];
    _peiSongpopView.delegate = self;
    [self.view addSubview:_peiSongpopView];
    
    _psp2View = [[PSP2View alloc] initWithFrame:CGRectMake(0,kScreen_Height, kScreen_Width, kScreen_Height)];
    _psp2View.dataArary = @[@"已完成",@"未完成"];
    _psp2View.delegate = self;
    [self.view addSubview:_psp2View];
    
    
    
    
    

    
}


- (void)selectMainBtnAction:(UIButton *)sender {
    _peiSongpopView.frame = CGRectMake(0,kScreen_Height, kScreen_Width, kScreen_Height);
    _psp2View.frame =CGRectMake(0,kScreen_Height, kScreen_Width, kScreen_Height);
   if(sender!=self.tempBtn){
    self.tempBtn.selected=NO;
       self.tempBtn=sender;
   }
    self.tempBtn.selected=YES;
    
    if (sender.selected == YES) {
        NSLog(@"---%ld",sender.tag);
        if (sender.tag == 102) {
            _peiSongpopView.frame =   CGRectMake(0,CGRectGetMaxY(_lieShouZhiWeiView.frame)+1, kScreen_Width, kScreen_Height);
        }
        if (sender.tag == 101) {
            _peiSongpopView.frame = CGRectMake(0,kScreen_Height, kScreen_Width, kScreen_Height);
            _psp2View.frame =CGRectMake(0,kScreen_Height, kScreen_Width, kScreen_Height);
        }
        
        if (sender.tag ==103) {
             _psp2View.frame =   CGRectMake(0,CGRectGetMaxY(_lieShouZhiWeiView.frame)+1, kScreen_Width, kScreen_Height);
        }
    }
    
    
}


#pragma mark 时间选择的代理事件
//选择时间的代理事件
- (void)selePeiSongIndepath:(NSIndexPath *)indepath title:(NSString *)titleStr{
    _peiSongpopView.frame = CGRectMake(0,kScreen_Height, kScreen_Width, kScreen_Height);
    [self.view showTextNoActivity:[NSString stringWithFormat:@"%@",titleStr] timeLength:1.5];
}
- (void)remoPopTableAction:(UIButton *)sender {
     _peiSongpopView.frame = CGRectMake(0,kScreen_Height, kScreen_Width, kScreen_Height);
}

#pragma mark 时间选择的代理事件
//选择状态的的代理事件
- (void)selePeiSongIndepath2:(NSIndexPath *)indepath title:(NSString *)titleStr{
   _psp2View.frame = CGRectMake(0,kScreen_Height, kScreen_Width, kScreen_Height);
    [self.view showTextNoActivity:[NSString stringWithFormat:@"%@",titleStr] timeLength:1.5];
    
}
- (void)remoPopTableAction2:(UIButton *)sender {
    _psp2View.frame = CGRectMake(0,kScreen_Height, kScreen_Width, kScreen_Height);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _dataArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSArray *teA = _dataArray[section];
    return  teA.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 60;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 70;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 70;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *bgV = [[UIView alloc] init];
    bgV.backgroundColor = KShouYeBg;
    
    UIView *bgV22 = [[UIView alloc] initWithFrame:CGRectMake(0, 10, kScreen_Width - 0,50)];
    bgV22.backgroundColor = [UIColor whiteColor];
    [bgV addSubview:bgV22];
    
    UIView *bgV2 = [[UIView alloc] initWithFrame:CGRectMake(20, 49, kScreen_Width - 40, 1)];
    bgV2.backgroundColor = KShouYeBg;
    [bgV22 addSubview:bgV2];
    
    
    
    
    
    UIImageView *imageV = [[UIImageView alloc] init];
    imageV.frame = CGRectMake(20, 17, 15, 15);
    imageV.image = [UIImage imageNamed:@"ddlb_shijian"];
    [bgV22 addSubview:imageV];
    
    
    
    
    //时间
    
    UILabel *la1 = [[UILabel alloc] init];
    la1.text = @"2017-09-28 17:23";
    la1.textColor = [UIColor blackColor];
    la1.frame = CGRectMake(CGRectGetMaxX(imageV.frame)+13, 15, 0, 20);
    la1.font = kFont14;
    [la1 sizeToFit];
    [bgV22 addSubview:la1];
    
    
    //状态
    UILabel *stateLB = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(la1.frame)+20, 15, 50, 20)];
    stateLB.text = @"已完成";
    stateLB.layer.masksToBounds = YES;
    stateLB.layer.cornerRadius = 10;
    stateLB.layer.borderColor = KBtnColor.CGColor;
    stateLB.textColor = KBtnColor;
    stateLB.layer.borderWidth = 0.5f;
    stateLB.font = kFont12;
    stateLB.textAlignment = NSTextAlignmentCenter;
    [bgV22 addSubview:stateLB];
    
    
    
    //价格
    UILabel *lb2 = [[UILabel alloc] initWithFrame:CGRectMake(kScreen_Width- 150, 15, 130, 20)];
    lb2.font = kFont15;
    lb2.text = @"¥20.0";
    lb2.textAlignment = NSTextAlignmentRight;
    lb2.textColor =KQiangGour;
    [bgV22 addSubview:lb2];
    
    
    
    return bgV;
    
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *bgV = [[UIView alloc] init];
    bgV.backgroundColor = [UIColor whiteColor];
    
    UIButton *btn1 = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn1.frame = CGRectMake(kScreen_Width/2-100,10, 200, 45);
    [btn1 setTitle:@"订单详情" forState:(UIControlStateNormal)];
    [btn1 setTitleColor:[UIColor lightGrayColor] forState:(UIControlStateNormal)];
    [btn1 setBackgroundColor: [UIColor whiteColor]];
    btn1.titleLabel.font = kFont15;
    btn1.layer.masksToBounds = YES;
    btn1.layer.cornerRadius = 45/2;
    btn1.layer.borderColor = KShouYeBg.CGColor;
    btn1.layer.borderWidth= 1.0f;
    [bgV addSubview:btn1];
    

    
    
    btn1.tag = 101;

    [btn1 addTarget:self action:@selector(handleHearAndFooBtntAction:) forControlEvents:(UIControlEventTouchUpInside)];

    
    return bgV;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    DingDanList2Cell *cell = [tableView dequeueReusableCellWithIdentifier:@"DingDanList2Cell"];
    cell.selectionStyle = kSeNone;
    if (indexPath.row == 1) {
        cell.shagndianLB.text = @"我也不知道名字的商店";
        cell.imageV.highlighted = YES;
        cell.addressLB.text = @" 不知道要送到什么地方才可以啊";
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    PublicMapVController *pub = [[PublicMapVController alloc] init];
    pub.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:pub animated:YES];
}

- (void)handleHearAndFooBtntAction:(UIButton *)sender {
    if (sender.tag == 101) {
        DingDanDetailViewController2 *vc = [[DingDanDetailViewController2 alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
     
    }
  
}

@end
